package com.java110.mall.shop.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.shop.ShopRangeRelDto;
import com.java110.po.shop.ShopRangeRelPo;
import com.java110.mall.shop.bmo.shopRangeRel.IDeleteShopRangeRelBMO;
import com.java110.mall.shop.bmo.shopRangeRel.IGetShopRangeRelBMO;
import com.java110.mall.shop.bmo.shopRangeRel.ISaveShopRangeRelBMO;
import com.java110.mall.shop.bmo.shopRangeRel.IUpdateShopRangeRelBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/shopRangeRel")
public class ShopRangeRelApi {

    @Autowired
    private ISaveShopRangeRelBMO saveShopRangeRelBMOImpl;
    @Autowired
    private IUpdateShopRangeRelBMO updateShopRangeRelBMOImpl;
    @Autowired
    private IDeleteShopRangeRelBMO deleteShopRangeRelBMOImpl;

    @Autowired
    private IGetShopRangeRelBMO getShopRangeRelBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /shopRangeRel/saveShopRangeRel
     * @path /app/shopRangeRel/saveShopRangeRel
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveShopRangeRel", method = RequestMethod.POST)
    public ResponseEntity<String> saveShopRangeRel(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shopRangeId", "请求报文中未包含shopRangeId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");


        ShopRangeRelPo shopRangeRelPo = BeanConvertUtil.covertBean(reqJson, ShopRangeRelPo.class);
        return saveShopRangeRelBMOImpl.save(shopRangeRelPo);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /shopRangeRel/updateShopRangeRel
     * @path /app/shopRangeRel/updateShopRangeRel
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateShopRangeRel", method = RequestMethod.POST)
    public ResponseEntity<String> updateShopRangeRel(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shopRangeId", "请求报文中未包含shopRangeId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "shopRangeRelId", "shopRangeRelId不能为空");


        ShopRangeRelPo shopRangeRelPo = BeanConvertUtil.covertBean(reqJson, ShopRangeRelPo.class);
        return updateShopRangeRelBMOImpl.update(shopRangeRelPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /shopRangeRel/deleteShopRangeRel
     * @path /app/shopRangeRel/deleteShopRangeRel
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteShopRangeRel", method = RequestMethod.POST)
    public ResponseEntity<String> deleteShopRangeRel(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "shopRangeRelId", "shopRangeRelId不能为空");


        ShopRangeRelPo shopRangeRelPo = BeanConvertUtil.covertBean(reqJson, ShopRangeRelPo.class);
        return deleteShopRangeRelBMOImpl.delete(shopRangeRelPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /shopRangeRel/queryShopRangeRel
     * @path /app/shopRangeRel/queryShopRangeRel
     * @param
     * @return
     */
    @RequestMapping(value = "/queryShopRangeRel", method = RequestMethod.GET)
    public ResponseEntity<String> queryShopRangeRel(@RequestParam(value = "shopRangeId", required = false) String shopRangeId,
                                                    @RequestParam(value = "shopId", required = false) String shopId,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        ShopRangeRelDto shopRangeRelDto = new ShopRangeRelDto();
        shopRangeRelDto.setPage(page);
        shopRangeRelDto.setRow(row);
        shopRangeRelDto.setShopRangeId(shopRangeId);
        shopRangeRelDto.setShopId(shopId);
        return getShopRangeRelBMOImpl.get(shopRangeRelDto);
    }
}
